package com.example.administrator.demo_one.VO;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.demo_one.R;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by ykbboom on 2017/1/18 21:21
 * email：ykbpro@whut.edu.cn
 */

/**
 * @author ykbboom
 * 功能:ListView适配器
*/
public class PeopleAdapter extends ArrayAdapter<People> {
    private int resourceId;
    public PeopleAdapter(Context context, int resource, List<People> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        People people = getItem(position);
        View view;
        ViewHolder viewHolder;
        if (convertView==null){
            view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.imageView = (ImageView) view.findViewById(R.id.peopleimage);
            viewHolder.textView = (TextView) view.findViewById(R.id.name);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.imageView.setImageResource(people.getImageId());
        viewHolder.textView.setText(people.getName());
        return view;
    }

    class ViewHolder{
        ImageView imageView;
        TextView textView;
    }
}
